<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>列表渲染 - Vue Lesson 3</title>
    <script src="bower_components/vue/dist/vue.min.js"></script>
</head>
<body>

<!-- 整数迭代 静态演示HTML时多行的写法 -->
<div id="demo1">
    <table>
        <tr v-for="n in 10">
            <td>{{ n }}</td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    var demo1 = new Vue({
        el: '#demo1',
        data: {

        }
    });

</script>
<!--/END 整数迭代 -->


<!--组件 和 v-for-->
<div id="todo-list-example">
    <input
            v-model="newTodoText"
            v-on:keyup.enter="addNewTodo"
            placeholder="Add a todo"
    >
    <ul>
        <li
                is="todo-item"
                v-for="(todo, index) in todos"
                v-bind:title="todo" :data-id="index"
                v-on:remove="todos.splice(index, 1)"
        ></li>
    </ul>
</div>
<script type="text/javascript">
    Vue.component('todo-item', {
        template: '\
    <li>\
      {{ title }}\
      <button v-on:click="$emit(\'remove\')">X</button>\
    </li>\
  ',
        props: ['title']
    });

    new Vue({
        el: '#todo-list-example',
        data: {
            newTodoText: '',
            todos: [
                'Do the dishes',
                'Take out the trash',
                'Mow the lawn'
            ]
        },
        methods: {
            addNewTodo: function () {
                this.todos.push(this.newTodoText)
                this.newTodoText = ''
            }
        }
    })
</script>

<!--/END 组件 和 v-for-->








</body>
</html>